#include <webx/menu.h>



class MainFrame : public webx::ProcessBase
{
protected:
	int process();
};

int MainFrame::process()
{
	int line = -1;

	param_string(flag);
	param_string(path);
	param_string(icon);
	param_string(title);
	param_string(source);
	param_string(keyword);
	
	if (title.empty()) title = "C++编译器";

	if (icon.empty()) icon = "/res/img/note/code.png";

	if (source.empty() && path.length() > 0 && path.length() < 1024)
	{
		HttpRequest request;

		request.init(path, true);
		request.setHeadValue("Cookie", this->request->getHeadValue("Cookie"));

		sp<HttpResponse> response = app->getLocaleResult(request);

		if (response)
		{
			SmartBuffer buffer = response->getResult();
			
			if (buffer.size() > 0 && buffer.size() < 256 * 1024) source = buffer.str();
		}
	}

	if (source.length() > 256 * 1024) source.clear();
	
	if (source.length() > 0)
	{
		if (keyword.length() > 0)
		{
			size_t pos = source.find(keyword);
			
			if (pos != string::npos)
			{
				line = 0;

				for (size_t i = 0; i < pos; i++)
				{
					if (source[i] == '\n') ++line;
				}
			}
		}

		source = stdx::replace(source, "\\", "\\\\");
		source = stdx::replace(source, "\n", "\\n");
		source = stdx::replace(source, "\r", "\\r");
		source = stdx::replace(source, "\t", "\\t");
		source = stdx::replace(source, "\"", "\\\"");
		source = stdx::replace(source, "\'", "\\\'");
	}
	out<<"<!DOCTYPE HTML>\r\n<html manifest=\'/res/etc/manifest.cache\'>\r\n<head>\r\n<title>";
	out<<(title);
	out<<"</title>\r\n<meta name=\'referrer\' content=\'always\'/>\r\n<link rel=\'shortcut icon\' href=\'";
	out<<(icon);
	out<<"\'/>\r\n<meta name=\'keywords\' content=\'C++在线编译器\'/>\r\n<meta name=\'description\' content=\'C++在线编译器\'/>\r\n<meta http-equiv=\'x-ua-compatible\' content=\'ie=edge,chrome=1\'/>\r\n<meta http-equiv=\'content-type\' content=\'text/html; charset=utf-8\'/>\r\n<meta name=\'viewport\' content=\'width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no\'/>\r\n\r\n<link rel=\'stylesheet\' type=\'text/css\' href=\'/app/workspace/css/base.css\'/>\r\n<link rel=\'stylesheet\' type=\'text/css\' href=\'/res/lib/codemirror/lib/codemirror.css\'/>\r\n<link rel=\'stylesheet\' type=\'text/css\' href=\'/res/lib/codemirror/addon/fold/foldgutter.css\'/>\r\n\r\n<script>\r\nif (typeof(require) == \'function\') delete window.module;\r\n</script>\r\n\r\n<script src=\'/res/lib/utils.js.gzip\'></script>\r\n<script src=\'/res/lib/codemirror/lib/codemirror.js.gzip\'></script>\r\n\r\n<script src=\'/res/lib/codemirror/mode/clike/clike.js\'></script>\r\n<script src=\'/res/lib/codemirror/addon/fold/foldcode.js\'></script>\r\n<script src=\'/res/lib/codemirror/addon/fold/foldgutter.js\'></script>\r\n<script src=\'/res/lib/codemirror/addon/fold/brace-fold.js\'></script>\r\n<script src=\'/res/lib/codemirror/addon/fold/indent-fold.js\'></script>\r\n<script src=\'/res/lib/codemirror/addon/fold/comment-fold.js\'></script>\r\n  \r\n<style>\r\n#SideDiv{\r\n\tbackground: #FFF;\r\n\tpadding-top: 3px;\r\n}\r\n#MainDiv{\r\n\tdisplay: none;\r\n}\r\n#CodeDiv{\r\n\tmargin-top: 2px;\r\n\tborder: 1px solid #CCC;\r\n}\r\n#OutputDiv{";
	if (flag == "V"){	out<<"\tdisplay: none;";
	}	out<<"\tpadding-top: 3px;\r\n\tborder: 1px solid #CCC;\r\n}\r\n#OutputText{\r\n\toverflow: scroll;\r\n\tmargin-top: 3px;\r\n\tborder-top: 1px solid #CCC;\r\n\tbackground: rgba(255, 255, 255, 0.6);\r\n}\r\n#CmdParamDiv{";
	if (flag == "V"){	out<<"\tdisplay: none;";
	}	out<<"}\r\n#CompileButton{\r\n\tcolor: #090;\r\n}\r\n#SaveCodeButton{\r\n\tcolor: #090;\r\n}\r\n.OutputPage{\r\n\tpadding: 0px 4px;\r\n\twhite-space: pre-wrap;\r\n\tword-wrap: break-word;\r\n}\r\n.MenuTableTd{\r\n\tpadding-right: 4px;\r\n}\r\n.CodeOperLink{\r\n\tfloat: right;\r\n\tmargin-left: 4px;\r\n\tmargin-right: 4px;\r\n\ttext-decoration: none;\r\n}\r\n.FileUploadButton{\r\n\theight: 18px;\r\n\tpadding: 0px 1px;\r\n\tline-height: 18px;\r\n}\r\n.CodeMirror{\r\n\tbackground: rgba(255, 255, 255, 0.6);\r\n}\r\n.CodeMirror-gutters{\r\n\tbackground: rgba(255, 255, 255, 0.7);\r\n}\r\n</style>\r\n\r\n<script>\r\nvar idx = 0;\r\nvar code = null;\r\nvar param = null;\r\nvar dbconn = null;\r\nvar menubar = null;\r\nvar menubox = null;\r\nvar viewcode = true;\r\nvar curtitle = null;\r\nvar curcontent = null;\r\n\r\nvar line = ";
	out<<(line);
	out<<";\r\nvar source = \'";
	out<<(source);
	out<<"\';\r\n\r\nif (typeof(require) == \'function\' && strlen(source) <= 0){\r\n\tloadScript(\'/sys/node.js\').onload = function(){\r\n\t\tvar path = shell.argv[1];\r\n\t\tif (path){\r\n\t\t\tvar pos = shell.size(path);\r\n\t\t\tif (pos > 8 && pos < 256 * 1024){\r\n\t\t\t\tsource = shell.read(path);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction addCode(saved){\r\n\tvar content = code.getValue();\r\n\r\n\tif (saved == null && strlen(content) > 0 && strlen(curtitle) > 0) saveCode(curtitle, content, false);\r\n\r\n\tvar msgbox = showConfirmMessage(\"<table class=\'DialogTable\'><tr><td><v-text id=\'AddCodeTitleText\' title=\'代码名称\' size=\'14\' maxlength=\'20\'></v-text></td></tr></table>\", \'新建代码\', function(flag){\r\n\t\tif (flag == 0) return true;\r\n\r\n\t\tvar title = $(\'#AddCodeTitleText\').val();\r\n\r\n\t\tif ((len = strlen(title)) == 0){\r\n\t\t\t$(\'#AddCodeTitleText\').focus();\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tif (len > 24){\r\n\t\t\tshowToast(\'代码名称最多12个汉字或24个英文字母\');\r\n\t\t\t$(\'#AddCodeTitleText\').focus();\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tdbconn.query(\'select * from cppcode where title=?\', [title], function(result){\r\n\t\t\tif (result.length > 0){\r\n\t\t\t\tshowToast(\'已有名称相同的代码\');\r\n\t\t\t\t$(\'#AddCodeTitleText\').focus();\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\thideMsgBox();\r\n\r\n\t\t\t\tremoveStorage(\"compile_cppcode\");\r\n\r\n\t\t\t\tif (curtitle == null && strlen(content) > 0) saved = true;\r\n\r\n\t\t\t\tsaveCode(title, saved ? content : source);\r\n\t\t\t}\r\n\t\t});\r\n\t\r\n\t\treturn false;\r\n\t});\r\n\t\r\n\t$(\'#AddCodeTitleText\').keydown(function(e){\r\n\t\tif (e.which == 13) msgbox.confirm();\r\n\t});\r\n}\r\n\r\nfunction exportCode(){\r\n\tdbconn.query(\'select * from cppcode\', function(result){\r\n\t\tif (result.length <= 0){\r\n\t\t\tshowToast(\'你还没有创建任何代码\');\r\n\t\t}\r\n\t\telse{\r\n\t\t\tsaveAs(JSON.stringify(result), getShortDateTimeString() + \'.code\');\r\n\t\t}\r\n\t});\r\n}\r\n\r\nfunction importCode(content){\r\n\ttry{\r\n\t\tvar num = 0;\r\n\t\tvar result = JSON.parse(content);\r\n\t\t\r\n\t\tif (result == null || result.length == null || result.length <= 0){\r\n\t\t\tshowToast(\'导入文件格式错误\');\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tfor (var i = 0; i < result.length; i++){\r\n\t\t\tvar item = result[i];\r\n\r\n\t\t\tif (strlen(item.title) > 0 && strlen(item.content) > 0){\r\n\t\t\t\tdbconn.execute(\'insert into cppcode(title,content,statetime) values(?,?,?)\', [unescape(item.title), unescape(item.content), item.statetime]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tsetTimeout(updateView, 100);\r\n\t\tshowToast(\'本地代码导入成功\');\r\n\t\treturn true;\r\n\t}\r\n\tcatch(e){\r\n\t\tshowToast(\'导入文件格式错误\');\r\n\t\treturn false;\r\n\t}\r\n}\r\n\r\nfunction removeCode(title){\r\n\tshowConfirmMessage(\'确定要将代码[\' + title + \']删除?\', \'删除代码\', function(flag){\r\n\t\tdbconn.execute(\'delete from cppcode where title=?\', [title],\r\n\t\t\tfunction(stmt, result){\r\n\t\t\t\tif (title == curtitle) curtitle = null;\r\n\t\t\t\tupdateView();\r\n\t\t\t}\r\n\t\t);\r\n\t});\r\n}\r\n\r\nfunction selectCode(title){\r\n\tdbconn.query(\'select * from cppcode where title=?\', [title], function(result){\r\n\t\t\tif (result.length > 0){\r\n\t\t\t\tcode.setValue(result[0].content);\r\n\t\t\t\tcurcontent = code.getValue();\r\n\t\t\t\tcurtitle = title;\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n}\r\n\r\nfunction saveCode(title, content, showtoast){\r\n\tif (showtoast == null) showtoast = true;\r\n\r\n\tif (title && title == curtitle){\r\n\t\tdbconn.execute(\'update cppcode set content=? where title=?\', [content, title],\r\n\t\t\tfunction(stmt, result){\r\n\t\t\t\tif (showtoast) showToast(\'代码保存成功\');\r\n\t\t\t\tcurcontent = content;\r\n\t\t\t\tupdateView();\r\n\t\t\t}\r\n\t\t);\r\n\t}\r\n\telse{\r\n\t\tif (title == null){\r\n\t\t\taddCode(true);\r\n\t\t}\r\n\t\telse{\r\n\t\t\tdbconn.execute(\'insert into cppcode(title,content,statetime) values(?,?,?)\', [title, content, getDateTimeString()], function(stmt, result){\r\n\t\t\t\tupdateView();\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction hideSideWindow(){\r\n\t$(\'#TopDiv\').remove();\r\n\t$(\'#SideDiv\').remove();\r\n\t$(\'#BottomDiv\').remove();\r\n\t$(\'#ImportCodeButton\').remove();\r\n\t$(\'#ExportCodeButton\').remove();\r\n}\r\n\r\nfunction updateView(){\r\n\tif (dbconn == null) return code.setValue(source);\r\n\r\n\tdbconn.query(\'select * from cppcode order by statetime desc\', function(result){\r\n\t\tvar time = null;\r\n\t\tvar label = null;\r\n\t\t\r\n\t\tmenubar.clear();\r\n\r\n\t\tif (result.length <= 0){\r\n\t\t\tcode.setValue(source);\r\n\t\t\tcurtitle = null;\r\n\t\t}\r\n\t\telse{\r\n\t\t\tresult.forEach(function(item){\r\n\t\t\t\tvar node = menubar.add(item.title, \'/res/img/file/cpp.png\', function(){\r\n\t\t\t\t\tvar content = code.getValue();\r\n\r\n\t\t\t\t\tif (strlen(content) == 0 || strlen(curcontent) == 0 || content == curcontent){\r\n\t\t\t\t\t\tselectCode(item.title);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\tshowConfirmMessage(\'是否要保存当前代码？\', \'保存代码\', function(flag){\r\n\t\t\t\t\t\t\tif (flag) saveCode(curtitle, content);\r\n\t\t\t\t\t\t\tselectCode(item.title);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\r\n\t\t\t\tmenubox.bind(node);\r\n\r\n\t\t\t\tif (strlen(curtitle) == 0){\r\n\t\t\t\t\tif (time == null || time < item.statetime){\r\n\t\t\t\t\t\ttime = item.statetime;\r\n\t\t\t\t\t\tlabel = node;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\tif (curtitle == item.title) label = node;\r\n\t\t\t\t}\r\n\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tif (label) label.click();\r\n\t});\r\n}\r\n\r\nfunction sponsor(){\r\n\tvar box = showToastMessage(\"<div style=\'width:256px;height:300px\'></div>\", true, null, null, function(){\r\n\t\t$(box.dialog).css(\'background-image\', \'\');\r\n\t});\r\n\t$(box.dialog).css(\'background-size\', \'100% 100%\').css(\'background-image\', \'url(/res/img/receipt.png)\');\r\n\tcenterWindow(box.dialog);\r\n}\r\n\r\nfunction compile(){\r\n\tvar cmd = param.val();\r\n\tvar output = $(\'#OutputText\');\r\n\tvar content = code.getValue();\r\n\r\n\tif (strlen(cmd) > 0xFF){\r\n\t\tshowToast(\'命令行参数太长\');\r\n\t\treturn param.focus();\r\n\t}\r\n\r\n\tif (!isFilePath(cmd, false)){\r\n\t\tshowToast(\'命令行参数不能有特殊字符\');\r\n\t\treturn param.focus();\r\n\t}\r\n\r\n\tif (strlen(content) == 0) return code.focus();\r\n\r\n\toutput.html(\'\');\r\n\r\n\tshowToastMessage(\'正在编译代码...\');\r\n\r\n\tif (!viewcode && dbconn == null) setStorage(\'compile_cppcode\', content);\r\n\r\n\tgetHttpResult(\'/compile/compile\', {code: content, param: cmd}, function(data){\r\n\t\thideToastBox();\r\n\r\n\t\tif (data.code == XG_PARAMERR){\r\n\t\t\tif (data.output){\r\n\t\t\t\toutput.html(\"<font color=\'#EE0000\'><pre class=\'OutputPage\'>\" + data.output + \"</pre></font>\");\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\toutput.html(\"<font color=\'#EE0000\'><pre class=\'OutputPage\'>源码编译失败</pre></font>\");\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (data.code == XG_TIMEOUT){\r\n\t\t\toutput.html(\"<font color=\'#EE0000\'><pre class=\'OutputPage\'>执行超时(源码中可能存在耗时操作)</pre></font>\");\r\n\t\t}\r\n\t\telse if (data.code == XG_SYSBUSY){\r\n\t\t\tif (idx++ < 50){\r\n\t\t\t\tcompile();\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tshowToast(\'系统繁忙---请稍后再试\');\r\n\r\n\t\t\t\tidx = 0;\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if (data.code < 0){\r\n\t\t\tif (data.status && data.status == 403){\r\n\t\t\t\tshowToast(\'访问频繁请稍后再试\');\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tshowToast(\'源码编译失败\');\r\n\t\t\t}\r\n\t\t}\r\n\t\telse{\r\n\t\t\toutput.html(\"<pre class=\'OutputPage\'>\" + data.output + \"</pre>\");\r\n\t\t}\r\n\t}, true);\r\n}\r\n\r\nfunction saveAs(text, filename){\r\n\tif (!!window.ActiveXObject || \'ActiveXObject\' in window){\r\n\t\tshowToast(\'当前浏览器不支持本地导出---您可以使用其他浏览器进行导出\');\r\n\t}\r\n\telse{\r\n\t\tvar a = document.createElement(\'a\');\r\n\r\n\t\ta.setAttribute(\'href\', \'data:text/plain,\' + escape(text));\r\n\t\ta.setAttribute(\'download\', filename);\r\n\t\ta.setAttribute(\'target\', \'_blank\');\r\n\t\ta.style.display = \'none\';\r\n\r\n\t\tappendCtrl(a);\r\n\t\ta.click();\r\n\r\n\t\t$(a).remove();\r\n\t}\r\n}\r\n\r\nfunction getFileContent(file, callback){\r\n\tif (window.FileReader){\r\n\t\tvar reader = new FileReader();\r\n\t\treader.onloadend = function(e){\r\n\t\t\tif (e.target.readyState == FileReader.DONE) callback(e.target.result);\r\n\t\t}\r\n\t\treader.readAsText(file);\r\n\t}\r\n};\r\n\r\nwindow.onload = function(){\r\n\tvar text = \"<div><span>我的代码</span><span style=\'float:right\'><a class=\'CodeOperLink\' style=\'color:#090;\' onclick=\'addCode()\' href=\'javascript:void(0)\'>添加</a><a class=\'CodeOperLink\' onclick=\'exportCode()\' href=\'javascript:void(0)\'>导出</a><a class=\'CodeOperLink\' onclick=\\\"$(\'#ImportCodeButton .FileUploadButton\').click()\\\" href=\'javascript:void(0)\'>导入</a></span>\";\r\n\tvar menucolor = {\r\n\t\tcolor: \'#234\',\r\n\t\tbarcolor: \'#FFF\',\r\n\t\tlistcolor: \'#FFF\',\r\n\t\thovercolor: \'#FFF\',\r\n\t\tselectcolor: \'#479\'\r\n\t};\r\n\r\n\tmenubox = new ContextMenu(\'MainDiv\', [\'打开\', \'删除\'], function(text, elem){\r\n\t\telem = $.pack(elem);\r\n\r\n\t\tif (text == \'删除\'){\r\n\t\t\tremoveCode(elem.text());\r\n\t\t}\r\n\t\telse{\r\n\t\t\telem.click();\r\n\t\t}\r\n\t});\r\n\r\n\tmenubar = new MenuBar(\'SideDiv\', text, \'/res/img/menu/folder.png\', null, false);\r\n\tmenubar.color(menucolor);\r\n\tgetVue(\'ContentDiv\');\r\n\r\n\ttry{\r\n\t\tdbconn = new DBConnect(\"compile_cppcode\");\r\n\t}\r\n\tcatch(e){\r\n\t\tdbconn = null;\r\n\t}\r\n\r\n\tif (strlen(source) == 0){\r\n\t\tviewcode = false;\r\n\r\n\t\tsource = getStorage(\"compile_cppcode\");\r\n\r\n\t\tif (strlen(source) == 0) source = getHttpResult(\'/app/compile/pub/compile.cpp\');\r\n\t}\r\n\telse{\r\n\t\t$(\'#SaveCodeButton\').remove();\r\n\t}\r\n\r\n\tvar height = getClientHeight();\r\n\r\n\twindow.onresize = function(){\r\n\t\theight = getClientHeight();\r\n\t";
	if (flag == "V"){	out<<"\t\t$(\'#CodeDiv\').height(height - 4);\r\n\t";
	}else{	out<<"\t\t$(\'#CodeDiv\').height(height - height / 5 - 66);\r\n\t\t$(\'#OutputText\').height(height / 5);\r\n\t";
	}	out<<"\t}\r\n\r\n\twindow.onresize();\r\n\r\n\t";
	if (flag == "V"){	out<<"\t\thideSideWindow();\r\n\t";
	}else{	out<<"\t\tif (dbconn == null){\r\n\t\t\thideSideWindow();\r\n\t\t}\r\n\t\telse{\r\n\t\t\tfunction updateContentView(){\r\n\t\t\t\tif (viewcode){\r\n\t\t\t\t\thideSideWindow();\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\tif (machinetype == \'PC\'){\r\n\t\t\t\t\t\tsetFrameStyle(\'TopDiv\', \'SideDiv\', \'MainDiv\', \'BottomDiv\', 0, 220, 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\t$(\'#ImportCodeButton\').remove();\r\n\t\t\t\t\t\t$(\'#ExportCodeButton\').remove();\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tdbconn.execute(\"create table cppcode(title text,content text,statetime text,primary key(title))\", function(dbconn, result){\r\n\t\t\t\tsaveCode(\'示例代码\', source);\r\n\t\t\t\tupdateContentView();\r\n\t\t\t},\r\n\t\t\tfunction(stmt, result){\r\n\t\t\t\tupdateContentView();\r\n\t\t\t});\r\n\t\t}\r\n\t";
	}	out<<"\tcode = CodeMirror.fromTextArea(document.getElementById(\'CodeText\'), {\r\n\t\tmode: \'text/x-csrc\',\r\n\t\ttabSize: 4,\r\n\t\tindentUnit: 4,\r\n\t\tinputStyle: \'textarea\',\r\n\t\tfoldGutter: true,\r\n\t\tlineNumbers: true,\r\n\t\tlineWrapping: true,\r\n\t\tmatchBrackets: true,\r\n\t\tindentWithTabs: true,\r\n\t\tstyleActiveLine: true,\r\n\t\tshowCursorWhenSelecting: true,\r\n\t\tgutters: [\'CodeMirror-linenumbers\', \'CodeMirror-foldgutter\']\r\n\t});\r\n\r\n\tcode.setSize(\'100%\',\'100%\');\r\n\tsetLabelText(\'CompileButton\', \'执行\');\r\n\tsetLabelText(\'SaveCodeButton\', \'保存\');\r\n\tsetLabelText(\'CopyCodeButton\', \'复制\');\r\n\tparam = QueryWidget(\'CmdParamDiv\', \'输入命令行程序启动参数\', \'执行\', compile);\r\n\r\n\t$(\'#MainDiv\').show();\r\n\r\n\t$(\'#SaveCodeButton\').click(function(){\r\n\t\tvar content = code.getValue();\r\n\r\n\t\tif (strlen(content) > 0){\r\n\t\t\tif (dbconn == null){\r\n\t\t\t\tsetStorage(\'compile_cppcode\', content);\r\n\r\n\t\t\t\tshowToast(\'代码保存成功\');\r\n\t\t\t}\r\n\t\t\telse{\r\n\t\t\t\tsaveCode(curtitle, content);\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n\r\n\t$(\'#CompileButton\').click(function(){\r\n\t\tcompile();\r\n\t});\r\n\r\n\tif (true){\r\n\t\topenbutton = new UploadFileWidget(\'ImportCodeButton\', \'导入\', null, 4 * 1024 * 1024);\r\n\t\tsetLabelText(\'ExportCodeButton\', \'导出\');\r\n\t\topenbutton.setFilter(\'.code\');\r\n\t\topenbutton.label.hide();\r\n\r\n\t\tif (getBrowserInfo().prefix == \'ms\'){\r\n\t\t\t$(\'#ExportCodeButton\').parent().remove();\r\n\t\t}\r\n\r\n\t\topenbutton.change(function(file){\r\n\t\t\tgetFileContent(file, function(text){\r\n\t\t\t\timportCode(text);\r\n\t\t\t});\r\n\t\t\treturn false;\r\n\t\t});\r\n\r\n\t\t$(\'#ExportCodeButton\').click(function(){\r\n\t\t\texportCode();\r\n\t\t});\r\n\t}\r\n\r\n\t$(\'#CopyCodeButton\').click(function(){\r\n\t\tvar clipboard = new Clipboard(\'#CopyCodeButton\', {\r\n\t\t\ttext: function(){\r\n\t\t\t\tshowToast(\'源码已复制到剪切板\');\r\n\t\t\t\treturn code.getValue();\r\n\t\t\t}\r\n\t\t});\r\n\t});\r\n\r\n\tcode.setValue(\'\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\');\r\n\r\n\t";
	if (flag == "V"){	out<<"\t\tcode.setValue(source);\r\n\t";
	}else{	out<<"\t\tif (viewcode){\r\n\t\t\tcode.setValue(source);\r\n\t\t}\r\n\t\telse{\r\n\t\t\tcode.setValue(\'\');\r\n\r\n\t\t\tsetTimeout(updateView, 100);\r\n\r\n\t\t\tif (machinetype == \'PC\'){\r\n\t\t\t\t$(\'body\').append(getHttpResult(\'/promote/adlistbar\', {left: 10, bottom: 6, width: 200, path: \'编程\'}));\r\n\t\t\t}\r\n\t\t}\r\n\t";
	}	out<<"\tif (line >= 0){\r\n\t\tsetTimeout(function(){\r\n\t\t\tcode.setSelection({line: line, ch: 0}, {line: line, ch: 1000}, {scroll: true});\r\n\t\t}, 500);\r\n\t}\r\n}\r\n</script>\r\n</head>\r\n\r\n<body>\r\n\t<div id=\'TopDiv\'></div>\r\n\t<div id=\'SideDiv\'></div>\r\n\t<div id=\'MainDiv\'>\r\n\t\t<div id=\'ContentDiv\'>\r\n\t\t\t<div id=\'CmdParamDiv\'></div>\r\n\t\t\t<div id=\'CodeDiv\'>\r\n\t\t\t\t<textarea id=\'CodeText\'></textarea>\r\n\t\t\t</div>\r\n\t\t\t<div id=\'OutputDiv\'>\r\n\t\t\t\t<table id=\'MenuTable\'>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td class=\'MenuTableTd\'>[程序输出]&nbsp;</td>\r\n\t\t\t\t\t\t<td class=\'MenuTableTd\'><input class=\'FileUploadButton\' id=\'CompileButton\' onfocus=\'this.blur()\' readonly/></td>\r\n\t\t\t\t\t\t<td class=\'MenuTableTd\'><input class=\'FileUploadButton\' id=\'SaveCodeButton\' onfocus=\'this.blur()\' readonly/></td>\r\n\t\t\t\t\t\t<td class=\'MenuTableTd\'><input class=\'FileUploadButton\' id=\'CopyCodeButton\' onfocus=\'this.blur()\' readonly/></td>\r\n\t\t\t\t\t\t<td class=\'MenuTableTd\'><span id=\'ImportCodeButton\'></span></td>\r\n\t\t\t\t\t\t<td class=\'MenuTableTd\'><input class=\'FileUploadButton\' id=\'ExportCodeButton\' onfocus=\'this.blur()\' readonly/></td>\r\n\t\t\t\t\t\t<td v-if=\"machinetype==\'PC\'\" class=\'MenuTableTd\'>&nbsp;&nbsp;<a class=\'TextLink\' onclick=\'sponsor()\' href=\'javascript:void(0)\'>赞助我们</a></td>\r\n\t\t\t\t\t\t<td v-if=\"machinetype==\'PC\'\" class=\'MenuTableTd\'>&nbsp;<a class=\'TextLink\' target=\'_blank\' href=\'/\'>赢锋主页</a></td>\r\n\t\t\t\t\t\t<td v-if=\"machinetype==\'PC\'\" class=\'MenuTableTd\'>&nbsp;<a class=\'TextLink\' target=\'_blank\' href=\'http://www.runoob.com/cplusplus/cpp-basic-syntax.html\'>学习教程</a></td>\r\n\t\t\t\t\t\t<td v-if=\"machinetype==\'PC\'\" class=\'MenuTableTd\'>&nbsp;<a class=\'TextLink\' target=\'_blank\' href=\'https://zh.cppreference.com/w/cpp\'>参考手册</a></td>\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t\t<div id=\'OutputText\'></div>\r\n\t\t\t</div>\r\n\t\t</div>\r\n\t</div>\r\n\t<div id=\'BottomDiv\'></div>\r\n</body>\r\n</html>";


	return XG_OK;
}
HTTP_WEBAPP(MainFrame, CGI_PRIVATE, "/compile/${filename}")